package com.soft.sitegenerator.business.hibernate;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import com.soft.sitegenerator.dao.HibernateDAO;
import com.soft.sitegenerator.exceptions.ObjectNotFoundException;

public class Sheet {

	private Long id;

	private String name;

	private String path;

	private String xhtml;

	private StyleSheet styleSheet;

	private Set sitePages = new HashSet();

	private Set webSites = new HashSet();

	private Set hookPoints = new HashSet();

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public Set getHookPoints() {
		return hookPoints;
	}

	public void setHookPoints(Set hookPoints) {
		this.hookPoints = hookPoints;
	}

	public Set getSitePages() {
		return sitePages;
	}

	public void setSitePages(Set sitePages) {
		this.sitePages = sitePages;
	}

	public Set getWebSites() {
		return webSites;
	}

	public void setWebSites(Set webSites) {
		this.webSites = webSites;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public StyleSheet getStyleSheet() {
		return styleSheet;
	}

	public void setStyleSheet(StyleSheet styleSheet) {
		this.styleSheet = styleSheet;
	}

	public String getXhtml() {
		return xhtml;
	}

	public void setXhtml(String xhtml) {
		this.xhtml = xhtml;
	}

	private HibernateDAO hibernateDAOHib;

	// HIBERNATE DAO
	public HibernateDAO getHibernateDAOHib() {
		return hibernateDAOHib;
	}

	public void setHibernateDAOHib(HibernateDAO hibernateDAOHib) {
		this.hibernateDAOHib = hibernateDAOHib;
	}

	public void load() throws ObjectNotFoundException {
		hibernateDAOHib.load(this, this.getId());
	}

	public void save() {
		hibernateDAOHib.save(this);
	}

	public void update() {
		hibernateDAOHib.update(this);
	}

	public void delete() {
		hibernateDAOHib.delete(this);
	}

	public boolean exist() {
		try {
			hibernateDAOHib.exist(this, this.getId());
			return true;
		} catch (ObjectNotFoundException e) {
			return false;
		}
	}

	public Collection findAll() {
		return hibernateDAOHib.find("from Sheet order by name");
	}

}
